package com.freemalll.merchant.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freemalll.merchant.domain.dto.MerInstallmentInfoCompetitiveDto;
import com.freemalll.merchant.domain.entity.MerInstallmentInfoCompetitive;
import com.freemalll.merchant.mapper.MerInstallmentInfoCompetitiveMapper;
import com.freemalll.merchant.service.MerInstallmentInfoCompetitiveService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author songshixiong
 * @since 2025-05-26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MerInstallmentInfoCompetitiveServiceImpl extends ServiceImpl<MerInstallmentInfoCompetitiveMapper, MerInstallmentInfoCompetitive> implements MerInstallmentInfoCompetitiveService {

    @Override
    public void batchInsert(List<MerInstallmentInfoCompetitiveDto> competitiveList, String installmentId) {
        if (CollectionUtils.isEmpty(competitiveList)) {
            return;
        }
        competitiveList.forEach(item -> {
            MerInstallmentInfoCompetitive competitive = MerInstallmentInfoCompetitive.builder()
                    .installmentId(installmentId)
                    .competitiveOrganizations(item.getCompetitiveOrganizations())
                    .competitiveRate(item.getCompetitiveRate())
                    .build();
            baseMapper.insert(competitive);
        });
    }

    @Override
    public List<MerInstallmentInfoCompetitiveDto> listByInstallmentId(String installmentId) {
        return baseMapper.listByInstallmentId(installmentId);
    }
}
